<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class UserRefQnr extends Model
{

    use HasFactory;

    /**
     * 关联到模型的数据表.
     *
     * @var string
     */
    protected $table = 'user_ref_qnr';

    /**
     * 可以被批量赋值的属性。
     *
     * @var array
     */
    protected $fillable = [
        'ref_id',
        'user_id',
        'qnr_id',
        'content',
    ];

    /**
     * 添加数据
     *
     * @param $data
     *
     * @return bool
     */
    public function saveData($data)
    {
        return $this->create($this->fill($data)->toArray()) ? true : false;
    }

    /**
     * 更新用户资料
     *
     * @param $data
     * @param $id
     *
     * @return bool
     */
    public function updateData($data,$id)
    {
        return $this->where('user_id',$id)->update($this->fill($data)->toArray()) ? true : false;
    }

    /**
     * 用户
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function admin_users()
    {
        return $this->belongsTo('App\Models\AdminUsers','user_id','id');
    }

    /**
     * 标签
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function qnr()
    {
        return $this->belongsTo('App\Models\Qnr','qnr_id','qnr_id');
    }
}
